<?php

use EasySwoole\DDL\DDLBuilder;

/**
 * migrate create
 * Class HttpTracker
 */
class HttpTracker
{
    /**
     * migrate run
     * @return string
     */
    public function up()
    {
        return "CREATE TABLE IF NOT EXISTS `http_tracker` (
  `point_id` varchar(50) NOT NULL,
  `parent_id` varchar(50) DEFAULT NULL,
  `point_name` varchar(255) DEFAULT NULL COMMENT '请求名称',
  `is_next` int(11) NOT NULL DEFAULT '0',
  `depth` int(11) NOT NULL DEFAULT '0',
  `status` varchar(10) NOT NULL DEFAULT '' COMMENT '状态',
  `repeated` tinyint(2) unsigned not null default '0' comment '是否复发请求',
  `ip` varchar(50) NOT NULL DEFAULT '' COMMENT '请求ip',
  `url` varchar(3000) NOT NULL DEFAULT '' COMMENT '请求地址',
  `request` json NOT NULL COMMENT '请求参数',
  `response` json NOT NULL COMMENT '响应参数',
  `server_name` varchar(20) NOT NULL DEFAULT '' COMMENT '运行服务器',
  `start_time` varchar(15) NOT NULL DEFAULT '0' COMMENT '请求开始时间',
  `end_time` varchar(15) NOT NULL DEFAULT '0' COMMENT '请求结束时间',
  `instime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '添加的时间戳',
  `runtime` int(10) unsigned NOT NULL DEFAULT '0' COMMENT '运行时间',
  PRIMARY KEY (`instime`, `point_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 PARTITION BY RANGE (`instime`)
(
	 PARTITION p202203 VALUES LESS THAN (1646064000) ENGINE = InnoDB,
	 PARTITION p202204 VALUES LESS THAN (1648742400) ENGINE = InnoDB,
	 PARTITION p202205 VALUES LESS THAN (1651334400) ENGINE = InnoDB,
	 PARTITION p202206 VALUES LESS THAN (1654012800) ENGINE = InnoDB,
	 PARTITION p202207 VALUES LESS THAN (1656604800) ENGINE = InnoDB,
	 PARTITION p202208 VALUES LESS THAN (1659283200) ENGINE = InnoDB,
	 PARTITION p202209 VALUES LESS THAN (1661961600) ENGINE = InnoDB,
	 PARTITION p202210 VALUES LESS THAN (1664553600) ENGINE = InnoDB,
	 PARTITION p202211 VALUES LESS THAN (1667232000) ENGINE = InnoDB,
	 PARTITION p202212 VALUES LESS THAN (1669824000) ENGINE = InnoDB,
	 PARTITION p202301 VALUES LESS THAN (1672502400) ENGINE = InnoDB,
	 PARTITION p202302 VALUES LESS THAN (1675180800) ENGINE = InnoDB,
	 PARTITION p202303 VALUES LESS THAN (1677600000) ENGINE = InnoDB,
	 PARTITION p202304 VALUES LESS THAN (1680278400) ENGINE = InnoDB,
	 PARTITION p202305 VALUES LESS THAN (1682870400) ENGINE = InnoDB,
	 PARTITION p202306 VALUES LESS THAN (1685548800) ENGINE = InnoDB,
	 PARTITION p202307 VALUES LESS THAN (1688140800) ENGINE = InnoDB,
	 PARTITION p202308 VALUES LESS THAN (1690819200) ENGINE = InnoDB,
	 PARTITION p202309 VALUES LESS THAN (1693497600) ENGINE = InnoDB,
	 PARTITION p202310 VALUES LESS THAN (1696089600) ENGINE = InnoDB,
	 PARTITION p202311 VALUES LESS THAN (1698768000) ENGINE = InnoDB,
	 PARTITION p202312 VALUES LESS THAN (1701360000) ENGINE = InnoDB,
	 PARTITION p202401 VALUES LESS THAN (1704038400) ENGINE = InnoDB,
	 PARTITION p202402 VALUES LESS THAN (1706716800) ENGINE = InnoDB,
	 PARTITION p202403 VALUES LESS THAN (1709222400) ENGINE = InnoDB,
	 PARTITION p202404 VALUES LESS THAN (1711900800) ENGINE = InnoDB,
	 PARTITION p202405 VALUES LESS THAN (1714492800) ENGINE = InnoDB,
	 PARTITION p202406 VALUES LESS THAN (1717171200) ENGINE = InnoDB,
	 PARTITION p202407 VALUES LESS THAN (1719763200) ENGINE = InnoDB,
	 PARTITION p202408 VALUES LESS THAN (1722441600) ENGINE = InnoDB,
	 PARTITION p202409 VALUES LESS THAN (1725120000) ENGINE = InnoDB,
	 PARTITION p202410 VALUES LESS THAN (1727712000) ENGINE = InnoDB,
	 PARTITION p202411 VALUES LESS THAN (1730390400) ENGINE = InnoDB,
	 PARTITION p202412 VALUES LESS THAN (1732982400) ENGINE = InnoDB
);";
    }

    /**
     * migrate rollback
     * @return string
     */
    public function down()
    {
        return DDLBuilder::dropIfExists('http_tracker');
    }
}
